package com.achievement.controller;

import com.achievement.domain.dto.honor.HonorApplyBookDTO;
import com.achievement.domain.dto.honor.HonorApplyInfoDTO;
import com.achievement.domain.dto.honor.ReviewPlanDTO;
import com.achievement.domain.param.honor.HonorApplyBookParam;
import com.achievement.domain.param.honor.HonorApplyInfoParam;
import com.achievement.domain.vo.honor.HonorApplyBookReviewVO;
import com.achievement.domain.vo.honor.HonorApplyInfoPersonnelVO;
import com.achievement.domain.vo.honor.HonorApplyInfoVO;
import com.achievement.service.IHonorApplyInfoService;
import com.achievement.service.IReviewPlanService;
import com.common.annotation.Anonymous;
import com.common.annotation.Log;
import com.common.core.controller.BaseController;
import com.common.core.domain.AjaxResult;
import com.common.core.page.TableDataInfo;
import com.common.enums.BusinessType;
import com.common.utils.CurrentRoleUtils;
import com.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
@Api(tags = "成果获奖-获奖申报")
@RestController
@RequestMapping("/achievement/honorApplyInfo")
public class HonorApplyInfoController extends BaseController {

    @Autowired
    private IHonorApplyInfoService honorApplyInfoService;

    @Autowired
    private IReviewPlanService reviewPlanService;
    @PreAuthorize("@ss.hasPermi('achievement:honorApplyInfo:list')")
    @ApiOperation("获取申报计划列表")
    @GetMapping("/list")
    public TableDataInfo list(HonorApplyInfoParam param)
    {
        startPage();
        String currentRoleKey = CurrentRoleUtils.getCurrentRoleKey(); //当前角色
        if("biz_kyms".equals(currentRoleKey)||currentRoleKey.equals("biz_kycgly")){
            List<HonorApplyInfoVO> list = honorApplyInfoService.selectByPage(param);
            return getDataTable(list);
        }else{
            List<HonorApplyInfoPersonnelVO> list = honorApplyInfoService.selectHonorApplyInfoPersonnelByPage(SecurityUtils.getUserId().toString());
            return getDataTable(list);
        }
    }
    /**
     * 左上方统计 全部 未启动 申报中 已停止
     * @param param 检索参数
     * @return AjaxResult
     */
    @PreAuthorize("@ss.hasPermi('achievement:honorApplyInfo:list-statistics')")
    @ApiOperation("管理员-获取申报计划左上方分组")
    @GetMapping(value = "/list-statistics")
    public AjaxResult listStatistics( HonorApplyInfoParam param)
    {
        List<HashMap<String, Integer>> list =honorApplyInfoService.listStatistics(param);
        return success(list);
    }

    /**
     * 获取获奖申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('achievement:honorApplyInfo:query')")
    @ApiOperation("获取申报计划详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(honorApplyInfoService.getInfoById(id));
    }

    /**
     * 新增获奖申请
     */
    @PreAuthorize("@ss.hasPermi('achievement:honorApplyInfo:add')")
    @ApiOperation("新增申报计划")
    @Log(title = "新增申报计划", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody HonorApplyInfoDTO dto)
    {
        return toAjax(honorApplyInfoService.add(dto));
    }

    /**
     * 修改获奖申请
     */
    @PreAuthorize("@ss.hasPermi('achievement:honorApplyInfo:update')")
    @ApiOperation("修改申报计划")
    @Log(title = "修改申报计划", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/update")
    public AjaxResult edit(@RequestBody HonorApplyInfoDTO dto)
    {
        return toAjax(honorApplyInfoService.update(dto));
    }

    /**
     * 删除获奖申请
     */
    @PreAuthorize("@ss.hasPermi('achievement:honorApplyInfo:remove')")
    @ApiOperation("删除申报计划")
    @Log(title = "删除申报计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/del/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(honorApplyInfoService.batchRemove(ids));
    }

    /**
     * 转入评审
     */
    @PreAuthorize("@ss.hasPermi('achievement:honorApplyInfo:changeReview')")
    @ApiOperation("转入评审")
    @PostMapping(value = "/changeReview")
    public AjaxResult changeReview(@RequestBody ReviewPlanDTO dto)
    {
        return toAjax(reviewPlanService.add(dto));
    }

    /**
     * 更新申报计划状态
     */
    @PreAuthorize("@ss.hasPermi('achievement:honorApplyInfo:updateStatusById')")
    @ApiOperation("更新申报计划状态applyState 启动1  结束2")
    @PutMapping(value = "/updateStatusById")
    public AjaxResult updateStatusById(@RequestBody HonorApplyInfoDTO dto)
    {
        return toAjax(honorApplyInfoService.updateStatusById(dto));
    }
}
